

<template>
<div>
  <h1>热门图书</h1>
  <div>

<!--  弹出借阅信息框  -->
    <el-dialog title="填写借阅信息" :visible.sync="dialogFormVisible" width="30%">
      <el-form label-width="80px" size="small">
        <el-form-item label="借阅人" >
          <el-input v-model="form.borrowUserName" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="邮箱" >
          <el-input v-model="form.borrowEmail" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" >
          <el-input v-model="form.borrowPhone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="书籍编号" >
          <el-input v-model="form.borrowBookId" autocomplete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="书籍信息" :visible.sync="dialogFormMessageVisible" width="30%">
      <el-form label-width="80px" size="small">
        <el-form-item label="书名" >
          <el-input v-model="bookName" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="作者" >
          <el-input v-model="author" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="类别" >
          <el-input v-model="bookType" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="书籍编号" >
          <el-input v-model="bookId" autocomplete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogFormMessageVisible = false">确 定</el-button>
      </div>
    </el-dialog>


    <br>
    <el-row type="flex" class="row-bg" justify="space-around">
      <el-col :span="6" v-for="book in books" :key="book.id" class="grid-content">
        <el-card :body-style="{ padding: '0px' }"  class="my-card">
          <img :src="book.image" class="image" />
          <div style="padding: 14px;">
            <span  class="center-text">{{ book.bookName }}</span>
            <br>
            <el-button type="text" @click="borrow">购买</el-button>
            <el-button type="text" @click="message(book.id)">查看信息</el-button>
            <el-button type="text" @click="">加入购物车</el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
  <div>
    <h1>交易详情</h1>

    <el-table :data="tableData" border stripe :header-cell-class-name="headerBg"  @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column prop="id" label="ID" width="80"></el-table-column>
      <el-table-column prop="borrowUserName" label="交易人" width="140"></el-table-column>
      <el-table-column prop="borrowPhone" label="手机号" width="120"></el-table-column>
      <el-table-column prop="borrowBookId" label="商品编号"></el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="success" @click="handleEdit(scope.row)">编辑<i class="el-icon-edit"></i></el-button>

          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="确定删除吗？"
              @confirm="handleDelete(scope.row.id)"
          >
            <el-button type="danger" slot="reference">删除<i class="el-icon-delete"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[2, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>

</div>
</template>

<script>
import request from "@/utils/request";

export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: "Borrow",
  data(){
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 5,
      books:[],
      bookName:"",
      author:"",
      bookType:"",
      bookId:"",
      dialogFormVisible: false,
      dialogFormMessageVisible:false,
      form:{},
      bookMsg:[],
      headerBg:"headerBg"
    };
  },
  created() {
    this.request.get("/book/image").then(res =>{
      this.books = res;
    });
    this.load();
  },
  methods:{
    save() {
      this.request.post("/borrow/save",this.form).then((res)=>{
        if (res){
          this.$message.success("借阅成功")
          this.dialogFormVisible = false;
          this.load();
        }else {
          this.$message.error("借阅失败失败")
        }
      })
    },
    borrow() {
      this.dialogFormVisible = true;
      this.load();
    },
    message(id) {
      this.request.get("/book/bookmsg/"+id).then(res =>{
          this.bookName = res.bookName;
          this.author = res.author;
          this.bookType = res.bookType;
          this.bookId = res.bookId;
      })
      this.dialogFormMessageVisible = true;

    },
    load(){
      request.get("/borrow/page",{
        params:{

          pageNum:this.pageNum,
          pageSize:this.pageSize,



        }
      }).then(res =>{

        console.log(res)
        this.tableData = res.records;
        this.total = res.total;

      })

    },
    handleCurrentChange(pageNum){
      console.log(pageNum)
      this.pageNum = pageNum;
      this.load()
    },
    handleSizeChange(pageSize){
      console.log(pageSize)
      this.pageSize = pageSize;
      this.load()
    }
  }


}
</script>



<style scoped>
.grid-content {
  height: 360px;
  border-radius: 4px;
  margin-bottom: 20px;
}
.image {
  width: 100%;
  display: block;
}
/*.center-text {
  text-align: center;
}*/

.my-card {
  transition: transform .2s; /* Animation */
}
.my-card:hover {
  transform: scale(1.05); /* (150% zoom - Note: if the zoom is too large, it will go outside of the viewport) */
}
.headerBg {
  background: #eeeeee !important;
}

</style>

